package com.shanghaionstar.nav.adapter;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.onstar.cn.common.util.CommonUtil;
import com.onstar.cn.framework.annotation.FindViewById;
import com.onstar.cn.framework.base.CommonAdapter;
import com.onstar.cn.framework.base.CommonViewHolder;
import com.onstar.cn.map.common.PoiItemInfo;
import com.shanghaionstar.R;
import com.shanghaionstar.enumtype.FunctionNameFindId;
import com.shanghaionstar.nav.model.PoiHistoryInfo;
import com.shanghaionstar.nav.presenter.NavMoreIssuedHistoryPresenter;
import com.shanghaionstar.nav.service.AbstractMapActivity;
import com.shanghaionstar.utils.BusinessUtil;

import java.util.List;

public class NavMoreIssuedHistoryAdapter extends CommonAdapter<PoiHistoryInfo> {
    private AbstractMapActivity mapActivity;
    private List<PoiHistoryInfo> mHistoryList;
    private NavMoreIssuedHistoryPresenter navMoreIssuedHistoryPresenter;

    public NavMoreIssuedHistoryAdapter(List<PoiHistoryInfo> datas, AbstractMapActivity mapActivity, NavMoreIssuedHistoryPresenter navMoreIssuedHistoryPresenter) {
        super(datas, mapActivity);
        this.mapActivity = mapActivity;
        mHistoryList = datas;
        this.navMoreIssuedHistoryPresenter = navMoreIssuedHistoryPresenter;
    }

    public void setList(List<PoiHistoryInfo> datas) {
        mHistoryList = datas;
    }

    @Override
    public void getView(final int position, CommonViewHolder viewHolder) {
        ViewHolder holder = (ViewHolder) viewHolder;
        PoiHistoryInfo poiHistoryInfo = mHistoryList.get(position);
        final PoiItemInfo poiItemInfo = poiHistoryInfo.getPoiItemInfo();

        String title = poiItemInfo.getTitle();
        if (!CommonUtil.isNull(title)) {
            holder.text_vendor_name.setText(title);
        } else {
            holder.text_vendor_name.setText("----");
        }
        String address = poiItemInfo.getAddress();
        if (!CommonUtil.isNull(address)) {
            holder.text_vendor_addres.setText(address);
        } else {
            holder.text_vendor_addres.setText("----");
        }
        holder.btn_sendtbt.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                BusinessUtil.sendReportByClickType(mapActivity, FunctionNameFindId.Morenavigationhistory_navigation.getStringValue());
                String msgTitle = "";
                if (mHistoryList.get(position) != null) {
                    navMoreIssuedHistoryPresenter.sendTbtOrOdd(mHistoryList.get(position).getPoiItemInfo());
                }
            }
        });

    }

    @Override
    public CommonViewHolder getViewHolder() {
        return new ViewHolder();
    }

    @Override
    public int layoutId() {
        return R.layout.nav_history_fav_listview_item;
    }

    private class ViewHolder extends CommonViewHolder {
        @FindViewById(R.id.text_vendor_name)
        TextView text_vendor_name;
        @FindViewById(R.id.text_vendor_addres)
        TextView text_vendor_addres;
        @FindViewById(R.id.btn_sendtbt)
        Button btn_sendtbt;
    }
}
